﻿@model vITs.Site.Models.DataModels.Assignment
@using vITs.Site.Models.DataModels
@using vITs.Site.Models
@{
    this.ViewBag.Title = "Rapport för Uppdrag: " + this.Model.AssignmentName;
    var totalSum = 0.0f + -this.Model.Advance;
}
<fieldset>
    <legend>
        <h2>@this.ViewBag.Title</h2>
    </legend>
    <fieldset>
        <legend>
            <h3>Uppdragsinformation</h3>
        </legend>
        <div>
            <p>
                Konsult: @this.Model.Consultant.GivenName @this.Model.Consultant.Surname
                <br />
                Handläggare: @this.Model.Handler.GivenName @this.Model.Handler.Surname
                <br />
                Tidsperiod: @this.Model.StartDate.ToString("yyyy-MM-dd") &mdash; @this.Model.EndDate.ToString("yyyy-MM-dd")
                <br />
                Förskott: @this.Model.Advance SEK
                <br />
                Status: @this.Model.GetStatus().GetDisplayName()
            </p>
        </div>
    </fieldset>
    @if (this.Model.Breaks.Count > 0)
    {
        <fieldset>
            <legend>
                <h3>Uppehåll</h3>
            </legend>
            <ul>
            @foreach (Break brk in this.Model.Breaks.OrderBy(b => b.StartDate))
	        {
                <li>@brk.StartDate.ToString("yyyy-MM-dd") &mdash; @brk.EndDate.ToString("yyyy-MM-dd")</li>
	        }
            </ul>
        </fieldset>
    }
    @if (this.Model.Trips.Count > 0)
    {
        var tripSum = 0.0d;
        
        <fieldset>
            <legend>
                <h3>Resor</h3>
            </legend>
            <ul>
                @foreach (Trip trip in this.Model.Trips.OrderBy(t => t.StartDate))
                {
                    <li>
                        <b>@trip.StartLocation &raquo; @trip.EndLocation</b>
                        <br />
                        @trip.StartDate.ToString("yyyy-MM-dd") &ndash; @trip.EndDate.ToString("yyyy-MM-dd")
                        <br />
                        @trip.GetTransportationMode().GetDisplayName(), @trip.TransportationCost
                        @if (trip.GetTransportationMode() == TransportationMode.Car)
                        {
                            var cost = trip.TransportationCost * 18.50d;
                            @:Mil (@cost SEK)

                            tripSum += cost;
                        }
                        else
                        {
                            tripSum += trip.TransportationCost;
                            @:SEK
                        }
                    </li>
                }
            </ul>
            <p>
                Total kostnad: @tripSum SEK
            </p>
        </fieldset>
        
        totalSum += tripSum;
    }
    @if (this.Model.PerDiems.Count > 0)
    {
        var perDiemSpecifications = new VitsDB().PerDiemSpecifications;
        var perDiemCost = 0d;
        
        <fieldset>
            <legend>
                <h3>Traktamenten</h3>
            </legend>
            <ul>
                @foreach (PerDiem pd in this.Model.PerDiems.OrderBy(p => p.Date))
	            {
                    var specification = perDiemSpecifications.SingleOrDefault(s => s.Country == pd.Country && s.Year == pd.Date.Year);
                    var cost = 0.0d;
                    cost += specification.Sum;
                    <li>
                        <b>@pd.Date.ToString("yyyy-MM-dd")</b> @pd.Country
                        <br />
                        @if (pd.Breakfast)
                        {
                            cost -= 44;
                            @: Frukost
                        }
                        @if (pd.Lunch)
                        {
                            cost -= 77;
                            @: Lunch
                        }
                        @if (pd.Dinner)
                        {
                            cost -= 77;
                            @: Middag
                        }
                        
                        <b>@cost SEK</b>
                    </li>
                    
                    perDiemCost += cost;
                }
            </ul>
            <p>
                Total Kostnad: @perDiemCost SEK
            </p>
        </fieldset>
        
        totalSum += perDiemCost;
    }
    @if (this.Model.Expenses.Count > 0)
    {
        var expensesCost = 0d;
        
        <fieldset>
            <legend>
                <h3>Utgifter</h3>
            </legend>
            <ul>
                @foreach (Expense exp in this.Model.Expenses.OrderBy(e => e.Date))
                {
                    <li>
                        <b>@exp.Name</b> &ndash; @exp.Sum @exp.Currency
                        @if (exp.Tax > 0)
                        {
                            var netto = @exp.Sum - @exp.Tax;
                            
                            @:(@netto @exp.Currency)
                        }
                        <br />
                        @exp.Date.ToString("yyyy-MM-dd") &nbsp;
                        @if (exp.Tax > 0)
                        {
                            @:Kvitto finns
                        }
                    </li>
                    
                    expensesCost += (exp.Sum * exp.ExchangeRate);
                }
            </ul>
            <p>
                Total Kostnad @expensesCost SEK
            </p>
        </fieldset>
        
        totalSum += expensesCost;
    }
    <p>Total kostnad för uppdraget: @totalSum SEK</p>
</fieldset>
@if (!this.ViewBag.Print)
{
    <a href="@String.Format("{0}Report/Assignment?AssignmentId={1}&Print=true", Utilities.BaseSiteUrl, this.Model.AssignmentId)" target="_blank">Utskriftsvänlig vy</a>
}
